package mq.rabbitmq.d_topic;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import mq.rabbitmq.ConnectionUtil;
import mq.rabbitmq.MqConstants;
import mq.rabbitmq.MyDefaultConsumer;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author shanzhenbo
 */
public class Consumer2 {

	public static void main(String[] args) throws IOException, TimeoutException {
		Connection connection = ConnectionUtil.getConnection();
		Channel channel = connection.createChannel();
		//声明交换机
		channel.exchangeDeclare(MqConstants.TOPIC_EXCHANGE, BuiltinExchangeType.TOPIC);
		//创建队列
		channel.queueDeclare(MqConstants.TOPIC_QUEUE_2, true, false, false, null);
		//队列绑定交换机
		channel.queueBind(MqConstants.TOPIC_QUEUE_2, MqConstants.TOPIC_EXCHANGE, "item.*");
		MyDefaultConsumer consumer = new MyDefaultConsumer(channel, "消费者2");
		channel.basicConsume(MqConstants.TOPIC_QUEUE_2, consumer);
	}

}
